var EventEmitter = require('events').EventEmitter;
var assign = require('object-assign');

class ListStore extends EventEmitter {

    constructor() {
        super();
        this.items = [];
    }

    getAll() {
        return this.items;
    }

    addNewItem(text) {
        this.items.push(text);
        setTimeout(function () {
            this.emitChange();
        }.bind(this), 1000);
    }

    emitChange() {
        this.emit("change");
    }

    addChangeListener(cb) {
        this.on('change', cb);
    }

    removeChangeListener(cb) {
        this.removeListener('change', cb);
    }
}
var ls = new ListStore();
module.exports = ls;

//var ListStore = assign({}, EventEmitter.prototype, {
//    items: [],
//    getAll: function () {
//        return this.items;
//    },
//    addNewItem: function (text) {
//        this.items.push(text);
//        setTimeout(function(){
//            this.emitChange();
//        }.bind(this), 1000);
//    },
//    emitChange: function () {
//        this.emit("change");
//    },
//    addChangeListener: function (cb) {
//        this.on('change', cb);
//    },
//    removeChangeListener: function (cb) {
//        this.removeListener('change', cb);
//    }
//});
// module.exports = ListStore;
